<template>
    <div id="app">
        <NavBar></NavBar>
        <b-container class="pt-4">
            <b-alert show dismissible variant="info">
                This is a beta version of sist2-admin. Please submit bug reports, usability issues and feature requests
                to the <a href="https://github.com/sist2app/sist2/issues/new/choose" target="_blank">issue tracker on
                Github</a>. Thank you!
            </b-alert>
            <router-view v-if="$store.state.sist2AdminInfo"/>
        </b-container>
    </div>
</template>

<script>
import NavBar from "@/components/NavBar";
import Sist2AdminApi from "@/Sist2AdminApi";

export default {
    components: {NavBar},
    data() {
        return {
            socket: null
        }
    },
    mounted() {
        Sist2AdminApi.getSist2AdminInfo()
            .then(resp => this.$store.commit("setSist2AdminInfo", resp.data));
        this.$store.dispatch("loadBrowserSettings");
        this.connectNotifications();
        // this.socket.onclose = this.connectNotifications;
    },
    methods: {
        connectNotifications() {
            if (window.location.protocol === "https:") {
                this.socket = new WebSocket(`wss://${window.location.host}/notifications`);
            } else {
                this.socket = new WebSocket(`ws://${window.location.host}/notifications`);
            }
            this.socket.onopen = () => {
                this.socket.send("Hello from client");
            }

            this.socket.onmessage = e => {
                const notification = JSON.parse(e.data);
                if (notification.message) {
                    notification.messageString = this.$t(notification.message).toString();
                }

                this.$store.dispatch("notify", notification)
            }
        }
    }
}
</script>

<style>
html, body {
    height: 100%;
}

#app {
    /*font-family: Avenir, Helvetica, Arial, sans-serif;*/
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /*text-align: center;*/
    color: #2c3e50;
    padding-bottom: 1em;
    min-height: 100%;
}

.info-icon {
    width: 1rem;
    min-width: 1rem;
    margin-right: 0.2rem;
    cursor: pointer;
    line-height: 1rem;
    height: 1rem;
    min-height: 1rem;
    background-image: url();
    filter: brightness(45%);
    display: block;
}

.tabs {
    margin-top: 10px;
}

.modal-title {
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

@media screen and (min-width: 1500px) {
    .container {
        max-width: 1440px;
    }
}

label {
    margin-top: 0.5rem;
    margin-bottom: 0;
}
</style>
